/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <chrono>

void merging(std::vector<int>& q) {
    for (int i = 0; i < q.size() - 1; i++) {
        for (int j = i + 1; j < q.size(); j++) {
            if (q[i] >= q[j]) {
                int t = q[j];
                q[j] = q[i];
                q[i] = t;
            }
        }
    }
}

int main() {
    std::string w = "m1_sorted (2).txt";
    std::string e = "m2_reverse.txt";
    std::string r = "m3_shuffle.txt";
    
    std::ifstream file1(w);
    std::ifstream file2(e);
    std::ifstream file3(r);
    
    std::vector<int> a;
    std::vector<int> b;
    std::vector<int> c;
    
    int num;
    while (file1 >> num) {
        a.push_back(num);
    }
    while (file2 >> num) {
        b.push_back(num);
    }
    while (file3 >> num) {
        c.push_back(num);
    }
    
    auto tim = [](std::vector<int>& n, const std::string& y) {
        auto t_start = std::chrono::high_resolution_clock::now();
        merging(n);
        auto t_finish = std::chrono::high_resolution_clock::now();
        std::cout << y << " " << std::chrono::duration_cast<std::chrono::milliseconds>(t_finish - t_start).count() << " milliseconds" << std::endl;
    };
    
    tim(a, w);
    tim(b, e);
    tim(c, r);
    
    return 0;
}
